/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.buzzwords.behaviors;

import com.buzzwords.utils.PMF;
import java.util.List;
import java.util.Map;
import javax.jdo.PersistenceManager;

/**
 *
 * @author potlow
 */
public abstract class DatabaseBehavior {
    protected PersistenceManager pm;

    public void createPm() {
        pm = PMF.get().getPersistenceManager();
    }

    public abstract boolean create(Object value);
    public abstract List<Object> read(Object value, List<String> properties);
    public abstract boolean update(Object value);
    public abstract boolean delete(Object value);
    public abstract List<Object> excute(String filter, String declareParameters,
            Map<String, Object> parameters, List<String> properties);
    //public abstract ObjectCounts getAll(int position, int pageSize, boolean ascending);


    protected boolean persist(Object object) {
        boolean didPersist = false;

        try {
            pm.makePersistent(object);
            didPersist = true;
        } finally {
            pm.close();
        }

        return didPersist;
    }

    /*protected boolean remove(Object object) {
        boolean didRemove = true;
        EntityManager em = emf.createEntityManager();
        try {
            em.getTransaction().begin();
            em.remove(em.merge(object));
            em.getTransaction().commit();
        } catch (Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
            em.getTransaction().rollback();
            didRemove = false;
        } finally {
            em.close();
        }
        return didRemove;
    }

    protected boolean merge(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.merge(object);
        em.getTransaction().commit();
        em.close();
        return true;
    }*/
}
